/*
 * 作者:熊猫
 * 日期:2017 - 3 - 19 7 - 10 - 13
 *
 */

package net.lainiao.morethread.Chapter7.demo6;

import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/3/19.
 */
public class Main {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Date startTime = new Date();
        MyWorkerThreadFactory myWorkerThreadFactory = new MyWorkerThreadFactory();
        ForkJoinPool pool = new ForkJoinPool(4, myWorkerThreadFactory, null, false);
        int[] array = new int[111111111];
        for (int i = 0; i < array.length; i++) {
            array[i] = 3;
        }
        MyRecursiveTask myRecursiveTask = new MyRecursiveTask(array, 0, array.length);
        pool.execute(myRecursiveTask);
        myRecursiveTask.join();
        pool.shutdown();
        pool.awaitTermination(1, TimeUnit.DAYS);
        System.out.println("Main Resoult For Value :" + myRecursiveTask.get());
        Date endTime = new Date();
        long ci = endTime.getTime() - startTime.getTime();
        System.out.println("Main Over " + ci + " milliseconds");
    }
}
